﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CuteWebUI;

public partial class Admin_Images : System.Web.UI.Page
{

    protected LocalFunctions FUNC;
    protected Int32 iGalleryID;
    protected void Page_Load(object sender, EventArgs e)
    {
        FUNC = ((Admin_AdminMasterPage)Master).FUNC;
       
            GetParameters();

            Dal.arParams.Clear();
            Dal.arParams.Add(1);
            Dal.arParams.Add(iGalleryID);
            DataSet DS = Dal.ExecuteDBspDS("RD_GetGalleryByID", Dal.arParams);
            if (DS != null)
            {
                // Set gallery title
                if (DS.Tables.Count > 0)
                {
                    lblTitle.Text = DS.Tables[0].Rows[0]["Title"].ToString();
                }
            }
            GetImagesData();
        
    }

    private void GetImagesData()
    {
        Dal.arParams.Clear();
        Dal.arParams.Add(iGalleryID);
        DataTable DT = Dal.ExecuteDBsp("Admin_GetImagesByGalID", Dal.arParams);
        dlGallery.DataSource = DT;
        dlGallery.DataBind();
    }

    private void GetParameters()
    {
        iGalleryID= Convert.ToInt32(Request.QueryString["Id"]);
    }

    protected void Uploader_FileUploaded(object sender, UploaderEventArgs e)
    {
        ////string sPath=Server.MapPath("~/Gallery/");
        ////string sFileName = Helper.GenerateUniqueFileName()+"."+e.FileName.Split('.')[1];
        ////e.CopyTo(sPath+sFileName);
        ////SaveToDB
        //Dal.arParams.Clear();
        //Dal.arParams.Add(iGalleryID);
        //Dal.arParams.Add(sFileName);
        //Dal.ExecuteDBsp("Admin_AddImage", Dal.arParams);

        //GetImagesData();
    }

    protected void imgDelete_Click(object sender, ImageClickEventArgs e)
    {
        int iImageID;
        Int32.TryParse(((ImageButton)sender).CommandArgument.ToString(), out iImageID);

        Dal.arParams.Clear();
        Dal.arParams.Add(iImageID);
        Dal.ExecuteDBsp("Admin_DeleteImage", Dal.arParams);
        GetImagesData();
    }
}
